﻿@model Project

@{
    ViewBag.Title = "DQAQS - Define Global Schema";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@using (Html.BeginForm()) {
    @Html.ValidationSummary(true)
    <fieldset>
        <legend>Project</legend>

        <div style="width:400px;  float:left; ">
        <div class="editor-label">
            @Html.LabelFor(model => model.Schema)
        </div>
        <div class="editor-field">
            @Html.TextAreaFor(model => model.Schema, new { style="width:300px; height:300px;", onkeydown="validateSchema(this)", id="schemaControl" })
            <p id="schemaError" class="field-validation-error"></p>
            @Html.ValidationMessageFor(model => model.Schema)
        </div>

        @Html.HiddenFor(model => model.Id)

        <p>
            <input type="submit" value="Save" />
        </p>
        </div>
        <div class="sidebar" style="float:left; width : 300px">
            <p class="label">
                Please define the schema using the following format:
            </p>
            <pre>
+TableName
--*KeyFieldPart1 ( FieldType )
--*KeyFieldPart2 ( FieldType )
--FieldName ( FieldType )
--FieldName2 ( FieldType )
</pre>
<p>Following example demonstrates the a schema definition. Please note that plus and minus signs are mandatory.
Every field must have a FieldType.
</p>
<p> Every table must have key defined.</p>
<p> <b>FieldType</b> : string, integer, number, datetime</p>
<pre>
+Customers
--*CustomerId ( integer )
--FullName ( string )
--Address ( string )
--DateOfBirth ( datetime )
</pre>
        </div>
    </fieldset>
<script>
    function validateSchema(ctrl) {
        $.getJSON("ValidateSchema?schema=" + escape(ctrl.value),
        function (data) {
            if (data.Error != undefined) {
                $("#schemaError").text(data.Error);
            }
            else {
                $("#schemaError").text("");
            }
        }
        );
    }
</script>
}
